package informationextraction;

import java.util.Iterator;
import java.util.List;

import xmlcommandset.SharedUserID;
import xmlparser.XMLInformationListener;
import xmlparser.XMLParser.AttributeContext;

public class SharedUserIdExtraction {
	XMLInformationListener xml_info = new XMLInformationListener();
	SharedUserID shared_user_id = new SharedUserID();
	
	public SharedUserIdExtraction(XMLInformationListener xml_info) {
		this.xml_info = xml_info;
	}
	
	public XMLInformationListener getXml_info() {
		return xml_info;
	}

	public void setXml_info(XMLInformationListener xml_info) {
		this.xml_info = xml_info;
	}

	public SharedUserID getShared_user_id() {
		return shared_user_id;
	}

	public void setShared_user_id(SharedUserID shared_user_id) {
		this.shared_user_id = shared_user_id;
	}

	
	
	public void setSharedUserID(){
		List<AttributeContext> list = xml_info.getList_attribute();
		Iterator<AttributeContext> itr = list.iterator();
		while(itr.hasNext()){
			AttributeContext attribute = itr.next();
			String str = attribute.getRuleContext().getText();
			if(str.contains("android:sharedUserId")){
				shared_user_id.setId_name(getSharesUserIDName(str));
			}
			//shared_user_id.setId_name("aa");
		}
	}

	public String getSharesUserIDName(String str) {
		// TODO Auto-generated method stub
		int index = str.indexOf("=");
		String name = str.substring(index);
		if(name.contains("\""))
			return name.substring(2,name.length()-1);
		return name;
	}
}
